/* GUI CONVERTED from rccpcmt.p (converter v1.75) Tue Apr 10 12:03:32 2001 */
/* rccpcmt.p - Release Management Customer Schedules                          */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.5.1.3 $                                                         */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3    LAST MODIFIED: 10/09/92   BY: WUG *G462*                  */
/* Oracle changes (share-locks)    09/12/94   BY: rwl *GM44*                  */
/* REVISION: 7.3    LAST MODIFIED: 11/15/96   BY: *G2J2* Suresh Nayak         */
/* REVISION: 8.5    LAST MODIFIED: 06/03/97   BY: *J1SK* Seema Varma          */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan           */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown           */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.5.1.3 $    BY: Jean Miller    DATE: 03/22/01 ECO: *P008*        */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* CUSTOMER PERIOD CALENDAR MAINT */

{mfdtitle.i "b+ "}

define variable next_per like cpcd_per.
define variable del-yn like mfc_logical initial no.

define buffer cpcd_temp for cpcd_det.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
cpc_cust       colon 30  ad_name at 50 no-label
   cpc_year       colon 30
   cpc_type       colon 30
   cpc_desc       colon 30
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   space(25)
   cpcd_per
   cpcd_start
   cpcd_end
with frame b down width 80 attr-space THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

mainloop:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


   prompt-for cpc_cust cpc_year cpc_type
   editing:

      /* FIND NEXT/PREVIOUS RECORD */
      {mfnp.i cpc_mstr cpc_cust cpc_cust cpc_cust cpc_cust cpc_cust}

      if recno <> ? then do:
         find ad_mstr where ad_addr = cpc_cust no-lock no-error.
         display
            cpc_cust
            ad_name when (available ad_mstr)
            cpc_year
            cpc_type
            cpc_desc.
      end.

   end.

   if not can-find(cm_mstr where cm_addr = input cpc_cust)
   then do:
      /*Not a valid customer */
      {pxmsg.i &MSGNUM=3 &ERRORLEVEL=3}
      undo, retry.
   end.

   if lookup(input cpc_type,"W,M") = 0 then do:
      /* Period Type must be weekly or monthly */
      {pxmsg.i &MSGNUM=8101 &ERRORLEVEL=3}
      next-prompt cpc_type.
      undo, retry.
   end.

   /* ADD/MOD/DELETE  */
   find cpc_mstr using
        cpc_cust and
        cpc_year and
        cpc_type
   no-error.

   if not available cpc_mstr then do:
      /* Adding New Record */
      {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
      create cpc_mstr.
      assign cpc_cust
         cpc_year
         cpc_type.
   end.

   find ad_mstr where ad_addr = cpc_cust no-lock no-error.

   /* STORE MODIFY DATE AND USERID */
   cpc_mod_date = today.
   cpc_userid   = global_userid.

   display
      ad_name when (available ad_mstr)
      cpc_year
      cpc_type
      cpc_desc.

   ststatus = stline[2].
   status input ststatus.

   del-yn = no.

   seta:
   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      set cpc_desc go-on("F5" "CTRL-D" ).

      /* DELETE */
      if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
      then do:
         del-yn = yes.
         /* Please confirm delete */
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn
                  &CONFIRM-TYPE='LOGICAL'}
         if not del-yn then undo seta.
      end.

      if del-yn then do:
         for each cpcd_det where
                  cpcd_cust = cpc_cust and
                  cpcd_year = cpc_year and
                  cpcd_type = cpc_type
         exclusive-lock:
            delete cpcd_det.
         end.

         delete cpc_mstr.

         clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
         del-yn = no.
         next mainloop.
      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   loopb:
   repeat with frame b width 80:
/*GUI*/ if global-beam-me-up then undo, leave.


      find last cpcd_det where
                cpcd_cust = cpc_cust and
                cpcd_year = cpc_year and
                cpcd_type = cpc_type
      no-lock no-error.

      next_per = if available cpcd_det then cpcd_per + 1 else 1.

      display
         next_per @ cpcd_per.

      prompt-for
         cpcd_per
      editing:
         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp05.i cpcd_det cpcd_per
            "cpcd_cust = cpc_cust and
                cpcd_year = cpc_year and
                cpcd_type = cpc_type"
            cpcd_per cpcd_per}
         if recno <> ? then display cpcd_per cpcd_start cpcd_end.
      end.

      /* ADD/MOD/DELETE  */
      find cpcd_det where
           cpcd_cust = cpc_cust and
           cpcd_year = cpc_year and
           cpcd_type = cpc_type and
           cpcd_per  = input cpcd_per
      exclusive-lock no-error.

      if not available cpcd_det then do:
         /* ADDING NEW RECORD */
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
         create cpcd_det.
         assign
            cpcd_cust = cpc_cust
            cpcd_year = cpc_year
            cpcd_type = cpc_type
            cpcd_per  = input cpcd_per.
      end.
      else do:
         /* MODIFYING EXISTING RECORD */
         {pxmsg.i &MSGNUM=10 &ERRORLEVEL=1}
      end.

      recno = recid(cpcd_det).

      ststatus = stline[2].
      status input ststatus.

      del-yn = no.

      display
         cpcd_start
         cpcd_end.

      setb:
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         set
            cpcd_start
            cpcd_end
         go-on (F5 CTRL-D).

         /* DELETE */
         if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
         then do:
            del-yn = yes.
            /* Please confirm delete */
            {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn
                     &CONFIRM-TYPE='LOGICAL'}
         end.

         if cpcd_start = ?  then do:
            /* Invalid Date */
            {pxmsg.i &MSGNUM=27 &ERRORLEVEL=3}
            next-prompt cpcd_start.
            undo setb, retry.
         end.

         if cpcd_end = ? then do:
            /* Invalid Date */
            {pxmsg.i &MSGNUM=27 &ERRORLEVEL=3}
            next-prompt cpcd_end.
            undo setb, retry.
         end.

         if not del-yn then do:

            if cpcd_det.cpcd_end < cpcd_det.cpcd_start
            then do:
               /* END DATE CANNOT BE BEFORE START DATE */
               {pxmsg.i &MSGNUM=123 &ERRORLEVEL=2}
            end. /* IF cpcd_det.cpcd_end < cpcd_det.cpcd_start */
            else do:
               /* CHECK FOR OVERLAPPING PERIODS */
               find first cpcd_temp
                    where cpcd_temp.cpcd_cust   = cpcd_det.cpcd_cust  and
                          cpcd_temp.cpcd_type   = cpcd_det.cpcd_type  and
                         (cpcd_temp.cpcd_year  <> cpcd_det.cpcd_year  or
                          cpcd_temp.cpcd_per   <> cpcd_det.cpcd_per)  and
                          cpcd_temp.cpcd_start <= cpcd_det.cpcd_start and
                          cpcd_temp.cpcd_end   >= cpcd_det.cpcd_start
               no-lock no-error.

               if not available cpcd_temp then
                  find first cpcd_temp where
                             cpcd_temp.cpcd_cust = cpcd_det.cpcd_cust  and
                             cpcd_temp.cpcd_type = cpcd_det.cpcd_type  and
                            (cpcd_temp.cpcd_year <> cpcd_det.cpcd_year  or
                             cpcd_temp.cpcd_per   <> cpcd_det.cpcd_per)  and
                             cpcd_temp.cpcd_start <= cpcd_det.cpcd_end   and
                             cpcd_temp.cpcd_end   >= cpcd_det.cpcd_end
                  no-lock no-error.

               if not available cpcd_temp then
                  find first cpcd_temp where
                             cpcd_det.cpcd_cust   = cpcd_temp.cpcd_cust  and
                             cpcd_det.cpcd_type   = cpcd_temp.cpcd_type  and
                            (cpcd_det.cpcd_year  <> cpcd_temp.cpcd_year  or
                             cpcd_det.cpcd_per   <> cpcd_temp.cpcd_per)  and
                             cpcd_det.cpcd_start <= cpcd_temp.cpcd_start and
                             cpcd_det.cpcd_end   >= cpcd_temp.cpcd_start
                  no-lock no-error.

               if not available cpcd_temp then
                  find first cpcd_temp where
                             cpcd_det.cpcd_cust   = cpcd_temp.cpcd_cust  and
                             cpcd_det.cpcd_type   = cpcd_temp.cpcd_type  and
                            (cpcd_det.cpcd_year  <> cpcd_temp.cpcd_year  or
                             cpcd_det.cpcd_per   <> cpcd_temp.cpcd_per)  and
                             cpcd_det.cpcd_start <= cpcd_temp.cpcd_end   and
                             cpcd_det.cpcd_end   >= cpcd_temp.cpcd_end
                  no-lock no-error.

               if available cpcd_temp then do:
                  /* DATE RANGES MAY NOT OVERLAP */
                  {pxmsg.i &MSGNUM=122 &ERRORLEVEL=2}
               end. /* IF NOT AVAILABLE cpcd_temp */

               else do: /* IF NOT AVAILABLE cpcd_temp */

                  /* CHECK FOR  OUT OF SEQUENCE PERIODS */
                  find first cpcd_temp where
                     cpcd_det.cpcd_cust  = cpcd_temp.cpcd_cust and
                     cpcd_det.cpcd_type  = cpcd_temp.cpcd_type and
                     cpcd_det.cpcd_year  = cpcd_temp.cpcd_year and
                     cpcd_det.cpcd_per   >  cpcd_temp.cpcd_per and
                     cpcd_det.cpcd_start < cpcd_temp.cpcd_end
                  no-lock no-error.

                  if not available cpcd_temp then
                     find first cpcd_temp where
                        cpcd_det.cpcd_cust = cpcd_temp.cpcd_cust and
                        cpcd_det.cpcd_type = cpcd_temp.cpcd_type and
                        cpcd_det.cpcd_year = cpcd_temp.cpcd_year and
                        cpcd_det.cpcd_per  < cpcd_temp.cpcd_per  and
                        cpcd_det.cpcd_end  > cpcd_temp.cpcd_start
                     no-lock no-error.

                  if available cpcd_temp then do:
                     /* PERIOD IS OUT OF SEQUENCE */
                     {pxmsg.i &MSGNUM=1838 &ERRORLEVEL=2}
                  end. /* IF AVAILABLE cpcd_temp */

               end. /* IF NOT AVAILABLE cpcd_temp */

            end . /* IF NOT cpcd_det.cpcd_end > cpcd_det.cpcd_start */

         end. /* IF NOT DEL-YN */

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*setb*/

      if del-yn then do:

         delete cpcd_det.

         clear frame b.
         del-yn = no.
         next loopb.

      end.

      else do:

         down 1.
         status input.

         next_per = cpcd_det.cpcd_per + 1.

      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*loopb*/

   clear frame b all.
   hide frame b.

end.
/*GUI*/ if global-beam-me-up then undo, leave.


status input.
